/*
 * Copyright (c) YouYuan 2018. https://gitee.com/you-yuan
 */

package com.yuan.crawler.common;

import com.gargoylesoftware.htmlunit.WebClient;
import org.apache.commons.logging.LogFactory;

import java.util.logging.Level;

/**
 * @author YouYuan
 * @version 1.0
 * @date 2018/9/7 12:11
 */
public class HtmlUnitCommon {

    public static WebClient initWebClient() {
        WebClient webClient = new WebClient();
        java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
        java.util.logging.Logger.getLogger("org.apache.http").setLevel(Level.OFF);
        LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log","org.apache.commons.logging.impl.NoOpLog");
        webClient.getOptions().setThrowExceptionOnScriptError(false);
        webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
        return webClient;
    }
}
